﻿@(Html.X().Panel()
    .Region(Region.West)
    .Layout(LayoutType.Fit)
    .Width(240)
    .Header(false)
    .Collapsible(true)
    .Split(true)
    .CollapseMode(CollapseMode.Mini)
    .Margins("0 0 4 4")
    .Border(false)
    .Items(items =>
    {
        items.Add(new TreePanel
        {
            ID = "exampleTree",
            Header = false,
            AutoScroll = true,
            Lines = false,
            UseArrows = true,
            CollapseFirst = false,
            RootVisible = false,
            HideHeaders = true,

            TopBar = 
            {
                new Toolbar
                {
                    Items = 
                    {
                        new TriggerField
                        {
                            ID = "SearchField",
                            AutoFocus = true,
                            EnableKeyEvents = true,
                            Flex = 1,
                            EmptyText = "Filter Examples...",
                            Triggers = 
                            {
                                new FieldTrigger
                                {
                                    HideTrigger = true,
                                    Icon = TriggerIcon.Clear                                    
                                }
                            },
                            Listeners = 
                            {
                                KeyUp = 
                                {
                                    Buffer = 100,
                                    Fn = "keyUp"
                                },
                                TriggerClick = 
                                {
                                    Fn = "clearFilter"    
                                },
                                SpecialKey = 
                                {
                                    Fn = "filterSpecialKey"
                                }
                            }
                        },
                        
                        new Button 
                        {
                            Icon = Icon.Cog,
                            ToolTip = "Options",
                            Menu = 
                            {
                                new Menu
                                {
                                    Items = 
                                    {
                                        new MenuItem
                                        {
                                            Text = "Expand All",
                                            IconCls = "icon-expand-all",
                                            Handler = "this.up('treepanel').expandAll(false);"
                                        },
                                        new MenuItem
                                        {
                                            Text = "Collapse All",
                                            IconCls = "icon-collapse-all",
                                            Handler = "this.up('treepanel').collapseAll(false);"
                                        },
                                        
                                        new MenuSeparator
                                        {
                                            Hidden = true
                                        },
                                        
                                        new CheckMenuItem
                                        {
                                            Text = "NEW Only",
                                            CheckHandler = "filterNewExamples",
                                            Hidden = true
                                        },
                                        
                                        new CheckMenuItem
                                        {
                                            Text = "Debug Mode",
                                            CheckHandler = "function (item, checked) { App.direct.ChangeScriptMode(checked); }",
                                            Checked = MvcResourceManager.GetInstance().SourceFormatting
                                        },
                                        
                                        new MenuSeparator(),
                                        
                                        new MenuItem
                                        {
                                            Text = "Theme",
                                            Icon = Icon.Paintcan,
                                            Menu = 
                                            {
                                                new Menu
                                                {
                                                    Items= 
                                                    {
                                                        new CheckMenuItem
                                                        {
                                                            Text = "Default",
                                                            Group = "theme"
                                                        },
                                                        new CheckMenuItem
                                                        {
                                                            Text = "Gray",
                                                            Checked = true,
                                                            Group = "theme"
                                                        },
                                                        new CheckMenuItem
                                                        {
                                                            Text = "Access",
                                                            Group = "theme"
                                                        },
                                                        new CheckMenuItem
                                                        {
                                                            Text = "Neptune",
                                                            Group = "theme"
                                                        }
                                                    },
                                                    
                                                    Listeners = 
                                                    {
                                                        Click = 
                                                        {
                                                            Fn = "themeChange"   
                                                        }   
                                                    }    
                                                }
                                            }
                                        }
                                    }    
                                }
                            }
                        }
                    }
                }
            },

            Store = 
            {
                new TreeStore
                {
                    Root = 
                    {
                        new Node
                        {
                            NodeID = "Root",
                            Expanded = true
                        }    
                    },
                    
                    Proxy = 
                    {
                        new AjaxProxy
                        {
                            API = 
                            {
                                Read = Url.Action("GetNavNodes")
                            },
                            
                            ActionMethods = 
                            {
                                Read = HttpMethod.GET    
                            }
                        }
                    },
                    
                    Fields =
                    {
                        new ModelField("isNew")
                    }
                }    
            },

            ColumnModel =
            {
                Columns =
                {
                    new TreeColumn()
                    {
                        Flex = 1,
                        Renderer =
                        {
                            Fn = "treeRenderer"
                        }   
                    }
                }
            },

            Listeners =
            {
                ItemClick =
                {
                    Handler = "onTreeItemClick(record, e);"
                },

                AfterRender =
                {
                    Fn = "onTreeAfterRender"
                }
            }
        });
    })
)